<template>
	<view class="page">
		<headnav leftText="更换学院"></headnav>
		<view class="block search">
			<view class="inner">
				<input type="text" class="input" value="" placeholder="搜索学院" @input="serchSchool"/>
				<image src="/static/img/ss.png" mode="" class="ssIcon"></image>
			</view>
		</view>
		<scroll-view class="scroll-v" scroll-y="true">
			<view class="items block">
				<view class="se-item" @tap="changeIitem(item.id)" :class="{active:item.id == currentId}" v-for="(item,index) in resoult" :key="index">
					{{item.name}}
				</view>
			</view>
		</scroll-view>
		<view class="bottoBt">
			<view class="bt bt-a" @tap="submit">确定</view>
		</view>
	</view>
</template>

<script>
import Cache from '../../util/cache'
	import { getCollege } from '@/api/user.js'
	export default {
		data() { 
			return {
			   currentId:-1,
			   list:[],
			   search:[]
			}
		},
		computed: {
			resoult() {
				if(this.search.length < 1) {
					return this.list
				} else {
					return  this.search
				}
			}
		},
		onLoad() {
			this.currentId = this.$Route.query.id;
			this.GetCollege();
		},
		methods: {
			async GetCollege() {
				// const { data } = await getCollege({id:this.user.college_id});
				const { data } = await getCollege({id:this.user.school_id});
				this.list = data;
				// console.log(this.list);
			},
			changeIitem(id) {
				this.currentId = id;
			},
			submit() {
				const name = this.list.filter((item) => {
				   return item.id == this.currentId
				})[0].name
				uni.$emit('pageBackData', { id: this.currentId, name: name }); 
				uni.navigateBack({  delta: 1 });
			},
			serchSchool(e) {
				let schoolName = e.detail.value;
				console.log(schoolName);
				this.search = this.list.filter((item) => {
					return item.name.indexOf(schoolName) >=0
				})
				// console.log(this.search);
			}
		}
	}
</script>

<style lang="scss">
   .page {
	   background-color: #f5f8fa;
	   @include pageCol
	   .search {
		   .inner {
			   .input {
				   width: 600rpx;
			   }
			   border-radius: 26rpx;
			   height: 93rpx;
			   display: flex;
			   background-color: #fff;
			   padding: 0 10rpx 0 30rpx;
			   align-items: center;
		        
			   .ssIcon {
				   width: 33rpx;
				   height: 33rpx;
			   }
		   }
		   .search {
			   background-color: #fff;
			   border-radius: 24rpx;
		   }
	   }
	   .scroll-v {
		   height: calc(100vh - 500rpx);
		   flex: none;
		   overflow: hidden;
		   padding-top: 30rpx;
		   .se-item {
			   border-radius: 30rpx;
			   background-color: #fff;
			   height: 112rpx;
			   margin-bottom:30rpx;
			   @include center;
			   &.active {
				   background-color: #388cff;
				   color:#fff;
			   }
		   }
	   }
	   .bottoBt {
		   padding-top: 40rpx;
		  @include bt-s-1;
	   }
   }
 
</style>
